<template>
    <el-dialog :title="showTitle" :visible="showDialog" width="50%" @close="btnCancel">
        <el-form label-width="80px" ref="addContract" :model="formData">
            <el-form-item label="阶段编码">
                <el-input v-model="formData.phaseCode"></el-input>
            </el-form-item>
            <el-form-item label="阶段名称">
                <el-input v-model="formData.phaseName"></el-input>
            </el-form-item>
            <el-form-item label="执行单据">
                <el-select
                    placeholder="请选择"
                    v-model="formData.bm_functionName"
                    @focus="getBillList"
                >
                    <el-option
                        v-for="(item, index) in functionName"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="执行内容">
                <el-input type="textarea" v-model="formData.phaseContent"></el-input>
            </el-form-item>
            <el-form-item label="序号">
                <el-input v-model="formData.sort"></el-input>
            </el-form-item>
            <el-row>
                <el-col :span="8">
                    <el-form-item label="是否开票" prop="status">
                             <el-switch
                                style="display: block"
                                v-model="formData.isInvoice"
                                active-color="#13ce66"
                                inactive-color="#8B8B8B"
                                :active-value="1"
                                :inactive-value="0"
                                :active-text="formData.isInvoice === 1 ? '是' : '否'"
                                
                            >
                            </el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="确认收入" prop="status">
                       <el-switch
                                style="display: block"
                                v-model="formData.isIncome"
                                active-color="#13ce66"
                                inactive-color="#8B8B8B"
                                :active-value="1"
                                :inactive-value="0"
                                :active-text="formData.isIncome === 1 ? '是' : '否'"
                                
                            >
                            </el-switch>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="启用状态" prop="status">
                        <el-switch
                                style="display: block"
                                v-model="formData.State"
                                active-color="#13ce66"
                                inactive-color="#8B8B8B"
                                :active-value="1"
                                :inactive-value="0"
                                :active-text="formData.State === 1 ? '是' : '否'"
                                
                            >
                            </el-switch>
                    </el-form-item>
                </el-col>
            </el-row>

            <el-form-item>
                <el-button
                    type="primary"
                    icon="el-icon-check"
                    style="position: absolute; right: 10px"
                    @click="btnOk"
                    >提交</el-button
                >
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
import { contractBillList, getBillList, saveBillList } from '@/api/apis/fileManagement'
export default {
    props: {
        showDialog: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            functionName: [],
            params: { page: '1', limit: '10', Sequence: 'descending', SequenceName: 'bm_id' },
            formData: {
                billid:'00000000-0000-0000-0000-000000000000',
                billKindID:'',
                createPersonID:'',
                updatePersonID:'',
                isdelete:null,
                phaseCode: '',
                phaseName: '',
                bm_functionName: '',
                phaseContent: '',
                sort: '',
                isInvoice: '',
                isIncome: '',
                State: '',
            },
        }
    },
    computed: {
        showTitle() {
            return this.formData.billid ? '编辑' : '新增'
        },
    },
    created() {},
    mounted() {
        this.getBillList()
    },
    methods: {
        //获取合同阶段档案列表数据
        async getBillList() {
            const { data } = await getBillList(this.params)
            data[1].map(item => {
                let _item = {
                    value: item.bm_id,
                    label: item.bm_functionName,
                }
                this.functionName.push(_item)
            })
            // this.functionName=data[1].bm_functionName
        },
        //点击提交
        async btnOk() {
            // 有id 修改
            if (this.formData.billid) {
                await this.$refs.addContract.validate()
                let obj={dataMain:this.formData}
                await saveBillList(obj)
                this.$message.success('操作成功')
                // 重新拉取数据
                this.$parent.getContractList()
                this.$emit('update:showDialog', false)
            }
            // 新增
            else {
             let obj={dataMain:this.formData}
              await saveBillList(obj)
              this.$message.success('操作成功')
              // 重新拉取数据
              this.$parent.getContractList()
              this.$emit('update:showDialog', false)
            }
        },
        //点击取消
        async btnCancel() {
            this.formData = {
                phaseCode: '',
                phaseName: '',
                bm_functionName: '',
                phaseContent: '',
                sort: '',
                isInvoice: '',
                isIncome: '',
                State: '',
            }
            this.$refs.addContract.resetFields() // 重置校验结果
            this.$emit('update:showDialog', false)
        },
    },
}
</script>

<style>
</style>